import { GCtrl } from "../../../Core/GCtrl";
import GPageView from "../../../Core/GView/GPageView";
import { AudioMgr } from "../../../Core/Manager/AudioMgr";
import { RedpointEffect, RedpointPos, RPointMask } from "../../Common/Define";
import { VIEW_ID, VIEW_PageNumByID } from "../../Common/UI";
import { Res } from "../../Common/UIResources";
import GameMgr from "../../Logic/GameMgr";

const { ccclass, property, menu, executeInEditMode } = cc._decorator;
@ccclass @menu('View/Home/HomeCtrl')

export default class HomeCtrl extends GPageView {   

    private _curIndex: number = 0;
    private isRecruit: boolean = true;
    public onGStart(page: number, ...args: any[]): void {
        AudioMgr.Ins().playMusic(Res.audio.main)
        super.onGStart(page, ...args);
        this.initEvent();
    }

    public initEvent() {
        GameMgr.redMgr.on(this.node, [
            { mask: [RPointMask.RPM_Hero_LvUp, RPointMask.RPM_Hero_UnLock, RPointMask.RPM_Hero_Tupo, RPointMask.RPM_Hero_AddStar, RPointMask.RPM_Have_Base], subPath: "bgNode/bottomNode/toggles/typeBtn1", effectType: RedpointEffect.REDPOINT, posType: RedpointPos.Main },
            { mask: [RPointMask.RPM_Go_To_Battle], subPath: "bgNode/bottomNode/toggles/typeBtn3", effectType: RedpointEffect.REDPOINT, posType: RedpointPos.Main },
            // { mask: [RPointMask.RPM_Have_Sync], subPath: "bgNode/bottomNode/toggles/typeBtn4", effectType: RedpointEffect.REDPOINT, posType: RedpointPos.Main },
        ])
    }

    // public onClickHandler(event:Event, str:string){
    //     AudioMgr.Ins().playEffect(Res.audio.btnClick)
    //     if (event.target._name == "typeBtn1"){
    //         GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.emailView);
    //     }
    // }

    /** 选中分页 */
    protected onSelected(nPage: number) {
        if (cc.js.isNumber(nPage)) {
            this.toggles[nPage].node.zIndex = 9;
            // cc.tween(this.toggles[nPage].node)
            //     .to(0.2, { position: cc.v2(0, 30) })
            //     .start()

            let page = (VIEW_PageNumByID[nPage]) ? VIEW_PageNumByID[nPage] : null;
            if (page && page.id) {
                let id = page.view;
                // 发送窗口开启事件
                if (!this.isRecruit) {
                    return
                }
                GCtrl.ES.emit(GCtrl.GClientWinOpenEventMsg, id);
            }
        }
    }

    /** 分页被取消 */
    protected onUnSelected(nPage: number) {
        if (cc.js.isNumber(nPage)) {
            this.toggles[nPage].node.zIndex = 0;
            // cc.tween(this.toggles[nPage].node)
            //     .to(0.2, { position: cc.v2(0, 0) })
            //     .start()
        }
    }
}   